const crypto = require("crypto");
let hash = crypto.createHash('md5');

// let str1 = 'this is first';

// hash.update(str1);
// let encodeStr = hash.digest('hex');
// console.log(encodeStr.length);

let str2 = 'this is second this is ...';
hash.update(str2);
let encodeStr2 = hash.digest('hex');
// console.log(encodeStr2.length);
console.log(encodeStr2);

//加密函数
function aesEncrypt(data, key) {
    let cipher  = crypto.createCipher('aes192',key);

    let returnStr = cipher.update(data,'utf-8','hex');
    let final = cipher.final('hex');
    returnStr = returnStr + final;
    return returnStr;
}

console.log(aesEncrypt('hello','node'));

//解密函数
function aesDecrypt(encrypted, key) {
    let decipher = crypto.createCipher('aes192',key);
    let decrypted = decipher.update(encrypted,'hex','utf-8');
    decrypted += decipher.final('utf-8');
    return decrypted;
}

console.log(aesDecrypt('2e4b8d2a9628d56c371b3d2e1744345a','node'));
